package com.cytech.cloudclinic.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.cytech.cloudclinic.R;
import com.yechaoa.yutils.YUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AddDoctorOrderDialog extends DialogFragment {

    @BindView(R.id.dialog_et_doctor_order)
    EditText doctorOrderEt;

    private OnSaveDoctorListener onSaveDoctorListener;

    public AddDoctorOrderDialog(OnSaveDoctorListener onSaveDoctorListener) {
        this.onSaveDoctorListener = onSaveDoctorListener;
    }

    @Override
    public void onStart() {
        super.onStart();
        WindowManager.LayoutParams lp = getDialog().getWindow().getAttributes();
        lp.width = (int) (0.9 * YUtils.getScreenWidth());
        getDialog().getWindow().setAttributes(lp);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.dialog_doctor_order, null);
        ButterKnife.bind(this, view);
        builder.setView(view);

        return builder.create();
    }

    @OnClick(R.id.dialog_doctor_order_cancel)
    public void onClickCancel(View view) {
        dismiss();
    }

    @OnClick(R.id.dialog_doctor_order_save)
    public void onClickSave(View view) {
        if(onSaveDoctorListener!=null){
            onSaveDoctorListener.onSave(doctorOrderEt.getText().toString());
        }
        dismiss();
    }

    public interface OnSaveDoctorListener{
        void onSave(String doctorOrderStr);
    }
}
